package com;

public class tuopu<String, Integer, Node> {
    public String name;
    public Integer indegree;//入度个数
    public List<Node> child=new List<Node>();//所指向的几点

    public java.lang.String toString() {
        return "Node [name=" + name + "]";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public Integer getIndegree() {
        return indegree;
    }

    public void setIndegree(Integer indegree) {
        this.indegree = indegree;
    }

    public List<Node> getChild() {
        return child;
    }

    public void setChild(List<Node> child) {
        this.child = child;
    }

    public void Node(String name) {
        this.name = name;
    }
    public tuopu(){}
    public void topSort(List<Node> vs) {
        Queue<Node> q = new Queue<Node>() {
            @java.lang.Override
            public boolean isEmpty() {
                return false;
            }
        };
        int size=vs.size();
        int count = 0;
        //初始化队列
        for (Node n = null;;) {
            if (n.indegree == 0)
                q.add(n);
        }
        //将入度为0的节点输出 并且将其所指向的节点的入度值-1
        while (!q.isEmpty()) {
            Node v = q.poll();
            count++;
            for (Node w : v.Queue()) {
                if (--w.indegree == 0)
                    q.add(w);
            }
        }
        //计算节点的个数和 最后出队列的个数 若不一样则有环
        if (count !=size) {

            java.lang.Object System = null;
            System.out.println(" 图有圈");
        }
    }


}
